﻿using IdentityServer4.EntityFramework.DbContexts;
using IdentityServer4.EntityFramework.Entities;
using IdentityServer4.EntityFramework.Options;

namespace Ids4.Api.Data.Mysql
{
    public class MysqlConfigurationDbContext : ConfigurationDbContext<MysqlConfigurationDbContext>
    {
        public MysqlConfigurationDbContext(DbContextOptions<MysqlConfigurationDbContext> options, ConfigurationStoreOptions storeOptions) : base(options, storeOptions)
        {

        }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.EnableSensitiveDataLogging();
            optionsBuilder.UseSnakeCaseNamingConvention();
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<ApiResource>().ToTable("api_resource");
            builder.Entity<ApiResourceScope>().ToTable("api_resource_scope");
            builder.Entity<ApiResourceClaim>().ToTable("api_resource_claim");
            builder.Entity<ApiResourceProperty>().ToTable("api_resource_property");
            builder.Entity<ApiResourceSecret>().ToTable("api_resource_secret");

            builder.Entity<ApiScope>().ToTable("api_scope");
            builder.Entity<ApiScopeClaim>().ToTable("api_scope_claim");
            builder.Entity<ApiScopeProperty>().ToTable("api_scope_property");

            builder.Entity<Client>().ToTable("client");
            builder.Entity<ClientClaim>().ToTable("client_claim");
            builder.Entity<ClientCorsOrigin>().ToTable("client_cors_origin");
            builder.Entity<ClientGrantType>().ToTable("client_grant_type");
            builder.Entity<ClientIdPRestriction>().ToTable("client_idp_restriction");
            builder.Entity<ClientPostLogoutRedirectUri>().ToTable("client_post_logout_redirecturi");
            builder.Entity<ClientProperty>().ToTable("client_property");
            builder.Entity<ClientRedirectUri>().ToTable("client_redirecturi");
            builder.Entity<ClientScope>().ToTable("client_scope");
            builder.Entity<ClientSecret>().ToTable("client_secret");
            builder.Entity<IdentityResource>().ToTable("identity_resource");
            builder.Entity<IdentityResourceClaim>().ToTable("identity_resource_claim");
            builder.Entity<IdentityResourceProperty>().ToTable("identity_resource_property");

        }
    }
}
